package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocCreditqueryDetailDao;
import com.irdstudio.cdp.pboc.service.domain.PbocCreditqueryDetail;
import com.irdstudio.cdp.pboc.service.facade.PbocCreditqueryDetailService;
import com.irdstudio.cdp.pboc.service.vo.PbocCreditqueryDetailVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 信贷审批查询记录明细				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocCreditqueryDetailService")
public class PbocCreditqueryDetailServiceImpl implements PbocCreditqueryDetailService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocCreditqueryDetailServiceImpl.class);

	@Autowired
	private PbocCreditqueryDetailDao pbocCreditqueryDetailDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocCreditqueryDetail(PbocCreditqueryDetailVO inPbocCreditqueryDetailVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocCreditqueryDetailVo.toString());
		int num = 0;
		try {
			PbocCreditqueryDetail pbocCreditqueryDetail = new PbocCreditqueryDetail();
			beanCopy(inPbocCreditqueryDetailVo, pbocCreditqueryDetail);
			num = pbocCreditqueryDetailDao.insertPbocCreditqueryDetail(pbocCreditqueryDetail);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocCreditqueryDetailVO inPbocCreditqueryDetailVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocCreditqueryDetailVo);
		int num = 0;
		try {
			PbocCreditqueryDetail pbocCreditqueryDetail = new PbocCreditqueryDetail();
			beanCopy(inPbocCreditqueryDetailVo, pbocCreditqueryDetail);
			num = pbocCreditqueryDetailDao.deleteByPk(pbocCreditqueryDetail);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditqueryDetailVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocCreditqueryDetailVO inPbocCreditqueryDetailVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocCreditqueryDetailVo.toString());
		int num = 0;
		try {
			PbocCreditqueryDetail pbocCreditqueryDetail = new PbocCreditqueryDetail();
			beanCopy(inPbocCreditqueryDetailVo, pbocCreditqueryDetail);
			num = pbocCreditqueryDetailDao.updateByPk(pbocCreditqueryDetail);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditqueryDetailVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocCreditqueryDetailVO queryByPk(PbocCreditqueryDetailVO inPbocCreditqueryDetailVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocCreditqueryDetailVo);
		try {
			PbocCreditqueryDetail queryPbocCreditqueryDetail = new PbocCreditqueryDetail();
			beanCopy(inPbocCreditqueryDetailVo, queryPbocCreditqueryDetail);
			PbocCreditqueryDetail queryRslPbocCreditqueryDetail = pbocCreditqueryDetailDao.queryByPk(queryPbocCreditqueryDetail);
			if (Objects.nonNull(queryRslPbocCreditqueryDetail)) {
				PbocCreditqueryDetailVO outPbocCreditqueryDetailVo = beanCopy(queryRslPbocCreditqueryDetail, new PbocCreditqueryDetailVO());
				logger.debug("当前查询结果为:"+ outPbocCreditqueryDetailVo.toString());
				return outPbocCreditqueryDetailVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditqueryDetailVO> queryAllOwner(PbocCreditqueryDetailVO pbocCreditqueryDetailVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocCreditqueryDetailVO> list = null;
		try {
			List<PbocCreditqueryDetail> pbocCreditqueryDetails = pbocCreditqueryDetailDao.queryAllOwnerByPage(pbocCreditqueryDetailVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocCreditqueryDetails.size());
			pageSet(pbocCreditqueryDetails, pbocCreditqueryDetailVo);
			list = (List<PbocCreditqueryDetailVO>) beansCopy(pbocCreditqueryDetails, PbocCreditqueryDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditqueryDetailVO> queryAllCurrOrg(PbocCreditqueryDetailVO pbocCreditqueryDetailVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocCreditqueryDetail> pbocCreditqueryDetails = pbocCreditqueryDetailDao.queryAllCurrOrgByPage(pbocCreditqueryDetailVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocCreditqueryDetails.size());
		List<PbocCreditqueryDetailVO> list = null;
		try {
			pageSet(pbocCreditqueryDetails, pbocCreditqueryDetailVo);
			list = (List<PbocCreditqueryDetailVO>) beansCopy(pbocCreditqueryDetails, PbocCreditqueryDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditqueryDetailVO> queryAllCurrDownOrg(PbocCreditqueryDetailVO pbocCreditqueryDetailVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocCreditqueryDetail> pbocCreditqueryDetails = pbocCreditqueryDetailDao.queryAllCurrDownOrgByPage(pbocCreditqueryDetailVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocCreditqueryDetails.size());
		List<PbocCreditqueryDetailVO> list = null;
		try {
			pageSet(pbocCreditqueryDetails, pbocCreditqueryDetailVo);
			list = (List<PbocCreditqueryDetailVO>) beansCopy(pbocCreditqueryDetails, PbocCreditqueryDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
	/**
	 * 查询操作
	 */
//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:通过reportId查询 信贷审批查询记录明细 获取最近三次征信查询reportId
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响实际业务
//	public List<PbocCreditqueryDetailVO> selectByReportId(PbocCreditqueryDetailVO inPbocCreditqueryDetailVo) throws Exception {
//
//		logger.debug("当前查询参数信息为:"+ inPbocCreditqueryDetailVo);
//		try {
//			PbocCreditqueryDetail queryPbocCreditqueryDetail = new PbocCreditqueryDetail();
//			beanCopy(inPbocCreditqueryDetailVo, queryPbocCreditqueryDetail);
//			List<PbocCreditqueryDetail> pbocCreditqueryDetails = pbocCreditqueryDetailDao.selectByReportId(queryPbocCreditqueryDetail);
//			if (Objects.nonNull(pbocCreditqueryDetails)) {
//				List<PbocCreditqueryDetailVO> pbocCreditqueryDetailVOS = (List<PbocCreditqueryDetailVO>)beansCopy(pbocCreditqueryDetails, PbocCreditqueryDetailVO.class);
//				logger.debug("当前查询结果为:"+ pbocCreditqueryDetailVOS.toString());
//				return pbocCreditqueryDetailVOS;
//			} else {
//				logger.debug("当前查询结果为空!");
//			}
//		} catch (Exception e) {
//			logger.error("查询数据发生异常!", e);
//			throw e;
//		}
//		return null;
//	}
//	/**
//	 * 需求编号:2019D0519
//	 * 问题编号:
//	 * 开发人员: caoxin
//	 * 创建日期:2019/7/19
//	 * 功能描述:通过reportId查询 信贷审批查询记录明细 获取最近三次征信查询reportId
//	 * 修改日期:2019/7/19
//	 * 修改描述:
//	 */
//	@Override
//	public List<PbocCreditqueryDetailVO> queryByReportIds(List<String> reportId) throws Exception {
//			logger.debug("当前查询参数信息为:"+ reportId);
//			List<PbocCreditqueryDetailVO> list = null;
//			try {
//				List<PbocCreditqueryDetail> pbocCreditqueryDetails = pbocCreditqueryDetailDao.queryByReportIds(reportId);
//				list = (List<PbocCreditqueryDetailVO>) beansCopy(pbocCreditqueryDetails, PbocCreditqueryDetailVO.class);
//			} catch (Exception e) {
//				logger.error("查询数据发生异常!", e);
//				throw e;
//			}
//			return list;
//	}
//
	@Override
	public PbocCreditqueryDetailVO queryAllByReportId(PbocCreditqueryDetailVO pbocCreditqueryDetailVO)
			throws Exception {
		logger.debug("当前查询参数信息为:"+ pbocCreditqueryDetailVO);

		try {
			PbocCreditqueryDetail pbocCreditqueryDetail = new PbocCreditqueryDetail();
			beanCopy(pbocCreditqueryDetailVO, pbocCreditqueryDetail);
			PbocCreditqueryDetail queryRslPbocCreditqueryDetail = pbocCreditqueryDetailDao.queryAllByReportId(pbocCreditqueryDetail);
			if (Objects.nonNull(queryRslPbocCreditqueryDetail)) {
				PbocCreditqueryDetailVO outPbocCreditqueryDetailVo = beanCopy(queryRslPbocCreditqueryDetail, new PbocCreditqueryDetailVO());
				logger.debug("当前查询结果为:"+ outPbocCreditqueryDetailVo);
				return outPbocCreditqueryDetailVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}

}
